//
//  ZYCTeaLeaveApproverHeaderView.m
//  ZDSC
//
//  Created by 张威 on 2021/11/6.
//

#import "ZYCTeaLeaveApproverHeaderView.h"
#import "BTImageTitleButton.h"

@interface ZYCTeaLeaveApproverHeaderView ()


@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIView *bgView;

@end
@implementation ZYCTeaLeaveApproverHeaderView

- (void)setApplyNode:(NSString *)applyNode{
    _applyNode = applyNode;
    _titleLabel.text = applyNode;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.bgView];
        [self addSubview:self.titleLabel];
        [self addSubview:self.selectButton];

        [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.equalTo(self);
            make.height.mas_equalTo(5.0f);
        }];

        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(15.0f);
            make.top.equalTo(self.bgView).offset(16.0f);
        }];

  
        [self.selectButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(-15.0f);
            make.centerY.equalTo(self.titleLabel);
        }];
        
    }
    return self;
}

- (BTImageTitleButton *)selectButton {
    if (!_selectButton) {
        _selectButton = [BTImageTitleButton buttonWithType:UIButtonTypeCustom];
        [_selectButton setTitle:@"全选" forState:UIControlStateNormal];
        [_selectButton setImage:[UIImage imageNamed:@"fxz"] forState:UIControlStateSelected];
        [_selectButton setImage:[UIImage imageNamed:@"xzz"] forState:UIControlStateNormal];
        [_selectButton addTarget:self action:@selector(clickSelectAction:) forControlEvents:UIControlEventTouchUpInside];
        [_selectButton setTitleColor:HEX_RGB(@"#41B166") forState:UIControlStateNormal];
        _selectButton.titleLabel.font = kCustomFont(@"PingFangSC-Regular", 13.0f);
    }
    return _selectButton;
}


- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Regular", 13) titleColor:HEX_RGB(@"333333") textAlignment:ZZTextAlignmentLeft];
    }
    return _titleLabel;
}

- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc] init];
        _bgView.backgroundColor = HEX_RGB(@"F9F9F9");
    }
    return _bgView;
}

- (void)clickSelectAction:(UIButton *)sender{
    sender.selected = !sender.selected;
    if ([self.delegate respondsToSelector:@selector(teaLeaveApproverHeaderViewClickAllSelect:)]) {
        [self.delegate teaLeaveApproverHeaderViewClickAllSelect:sender.selected];
    }
}
@end
